package com.typhoon.spring_jdbctemplate.consumer;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.typhoon.spring_jdbctemplate.constant.StoreReturnAddressEnum;
import com.typhoon.spring_jdbctemplate.container.CustomReturnAddressHolder;
import com.typhoon.spring_jdbctemplate.dao.UserDao;
import com.typhoon.spring_jdbctemplate.dao.support.PageQuery;
import com.typhoon.spring_jdbctemplate.dao.support.PageResult;
import com.typhoon.spring_jdbctemplate.entity.User;
import com.typhoon.spring_jdbctemplate.retry.AutoRefundContext;
import com.typhoon.spring_jdbctemplate.retry.AutoRefundManager;
import com.typhoon.spring_jdbctemplate.service.ReturnAddressService;
import com.typhoon.spring_jdbctemplate.service.UserService;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 模拟调用方
 * 
 * @author Typhoon
 * @date 2017-08-22 15:34 Tuesday
 * @since V1.3.1
 */
public class Consumer {

//	 static Map<String,String> map = new HashMap<>();
//	static {
//		//店铺与执行器映射关系
//		map.put(StoreReturnAddressEnum.STORE_A.getCode(),"store_a");
//		map.put(StoreReturnAddressEnum.STORE_B.getCode(),"store_b");
//	}
	public static void main(String[] args) {
		AbstractApplicationContext context = new ClassPathXmlApplicationContext("spring-root.xml");
		context.start();
		UserService userService = context.getBean(UserService.class);
		User user =  userService.selectById(1L);



//        AutoRefundManager autoRefundManager = context.getBean(AutoRefundManager.class);
//        autoRefundManager.autoRefund(new AutoRefundContext(122L,0));
//		CustomReturnAddressHolder returnAddressHolder = context.getBean("customReturnAddressHolder",CustomReturnAddressHolder.class);
//		String storeA = "store_a";
//		String storeB = "store_b";
//		String executorCodeA = null;
//		String executorCodeB = null;
//		for(Map.Entry<String,String> entry : map.entrySet()) {
//			if(entry.getValue().equals(storeA)) {
//				executorCodeA = entry.getKey();
//				continue;
//			}
//			if(entry.getValue().equals(storeB)) {
//				executorCodeB = entry.getKey();
//			}
//		}
//		ReturnAddressService storeAService = returnAddressHolder.getByCode(executorCodeA);
//		ReturnAddressService storeBService = returnAddressHolder.getByCode(executorCodeB);
//		System.out.println(storeAService.getAddress(1L));
//		System.out.println(storeBService.getAddress(2L));
	}
}
